<html>
<head>
  <title>XPaF Home</title>
  <link rel="stylesheet" type="text/css" href="xpaf.css">
</head>
<body>
<div id="content">
<div id="title">XPath-based Parsing Framework (XPaF)</div>

<h2>Description</h2>

XPath-based Parsing Framework (XPaF) is a simple,
fast, <a href="http://code.google.com/p/xpaf/">open-source</a> parsing framework
that makes it easy to extract relations (subject-predicate-object triples) from
HTML and XML documents.

<br><br>For a quick example, see below. When you're ready for more, check out
the <a href="tutorial.html">tutorial</a> or the <a href="faq.html">FAQ</a>.

<h2>Installation</h2>

Unix installation instructions are
available <a href="http://code.google.com/p/xpaf/source/browse/README">here</a>.

<h2>Quick example</h2>

Consider the following HTML snippet:

<pre class="codeblock">
&lt;table&gt;
  &lt;tr&gt;
    &lt;td class="name"&gt;Aaron&lt;/td&gt;
    &lt;td class="occ"&gt;Engineer&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td class="name"&gt;Jennifer&lt;/td&gt;
    &lt;td class="occ"&gt;Archeologist&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
</pre>

To extract name-occupation pairs from such tables, we'd write the following XPaF
parser:

<pre class="codeblock">
parser_name: "my_parser"
relation_tmpls {
  subject: "//td[@class='name']"
  predicate: "occupation"
  object: "//td[@class='occ']"

  subject_cardinality: MANY
  object_cardinality: MANY
}
</pre>

To run our parser, we'd write the following C++ code:

<pre class="codeblock">
XpafParserDefs parser_defs;
ReadXpafParserDefs("/path/to/my_parser.xpd", &parser_defs);
ParseOptions parse_options;
const XpafParserMaster master(parser_defs, parse_options);
ParsedDocument output;
master.ParseDocument(doc, &output);
</pre>

For the HTML snippet and parser above, XPaF would produce the following output,
encoded as
a <a href="http://code.google.com/p/xpaf/source/browse/src/parsed_document.proto#44"><tt>ParsedDocument</tt></a>
protocol buffer object:

<pre class="codeblock">
parser_name: "my_parser"
relations {
  subject: "Aaron"
  predicate: "occupation"
  object: "Engineer"
}
relations {
  subject: "Jennifer"
  predicate: "occupation"
  object: "Archeologist"
}
</pre>

For a more detailed example, check out the <a href="tutorial.html">tutorial</a>.

<br><br>The full parser specification language can be found
<a href="http://code.google.com/p/xpaf/source/browse/src/xpaf_parser_def.proto">here</a>
(start with <tt>XPafParserDef</tt>).

<h2>Chrome extension</h2>

The <a href="https://chrome.google.com/webstore/detail/hgimnogjllphhhkhlmebbmlgjoejdpjl">XPath
Helper Chrome extension</a> makes it easy to extract, edit, and evaluate XPath
queries on any webpage. It's very helpful for writing XPaF parsers.

<br><br>The source code for XPath Helper is
available <a href="http://code.google.com/p/xpaf/source/browse/#hg%2Fchrome">here</a>.

</div>
<div id="footer"><em>Adam Sadovsky</em></div>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="prettify.js"></script>
</body>
</html>
